package com.dumovie.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dumovie.utils.MapUtils;
import com.dumovie.utils.QiniuUtil;
import com.qiniu.storage.model.FileInfo;

@Controller
public class QiniuController {
	@RequestMapping("/qiniu/manager")
	public String qiniuManager(Model model,String prefix) {
		// 取得七牛视频文件夹下的文件列表
		FileInfo[] items = QiniuUtil.getFilesList(prefix);
		List<Map<String,Object>> files = new ArrayList<Map<String,Object>>();
		for (FileInfo fileInfo : items) {
			Date d = new Date(fileInfo.putTime/10000);
			files.add(MapUtils.of("key",fileInfo.key,"date",DateFormatUtils.format(d, "yyyy-MM-dd HH:mm:ss")));
		}
		model.addAttribute("files", files);
		return "/maintenanceSingle/qiniu";
	}
	
	/**
	 * 上传页
	 * @param model
	 * @return
	 */
	@RequestMapping("/qiniu/uploadpage")
	public String qiniuUploadpage(Model model) {
		return "/maintenanceSingle/uploadpage";
	}
	/**
	 * 上传文件
	 * @param model
	 * @return
	 */
	@RequestMapping("/qiniu/upload")
	public String qiniuUpload(Model model) {
		return "/maintenanceSingle/uploadpage";
	}
}
